package com.heima.controller;


import com.heima.Result;
import com.heima.domain.po.Drugs;
import com.heima.domain.query.DrugsQuery;
import com.heima.service.IDrugsService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 药物信息表 前端控制器
 * </p>
 *
 * @author author
 * @since 2025-08-04
 */
@Tag(name = "药物信息相关接口")
@RestController
@RequestMapping("/drugs")
public class DrugsController {
    @Autowired
    private IDrugsService drugsService;
    @Operation(summary = "分页查询药物信息")
    @GetMapping("/page")
    public Result findByPage(DrugsQuery drugsQuery) {
        return drugsService.findByPage(drugsQuery);
    }
    @Operation(summary = "根据id查询药物信息")
    @GetMapping("/get/{id}")
    public Result getById(@PathVariable Integer id) {
        Drugs drugs = drugsService.getById(id);
        if (drugs == null) {
            return Result.error("药物信息不存在");
        }
        return Result.success(drugs);
    }
}
